home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 15 / macformat_15.iso / C de cerca / Codewarrior Lite / MacOS Support / Headers / ANSI Headers / strstream < prev    next >
Text File  |  1995-12-29  |  3KB  |  127 lines

  1. // strstream standard header
  2. #ifndef _STRSTREAM_
  3. #define _STRSTREAM_
  4. #include <istream>
  5. #include <ostream>
  6.  
  7. #if __MWERKS__
  8. #pragma options align=mac68k
  9.  
  10. #if __CFM68K__ && __USING_IMPORTED_ANSI__
  11. #pragma import on
  12. #endif
  13. #endif
  14.  
  15.   // constants
  16. const int _ALSIZE = 512; // default allocation size
  17. const int _MINSIZE = 32; // minimum allocation size
  18.   // class strstreambuf
  19. class strstreambuf : public streambuf {
  20. public:
  21.  enum __Strstate {_Allocated = 1, _Constant = 2,
  22.   _Dynamic = 4, _Frozen = 8, _Noread = 16,
  23.   _Strzero = 0};
  24.  _BITMASK(__Strstate, _Strstate);
  25.  strstreambuf(int _N = 0)
  26.   {_Init(_N); }
  27.  strstreambuf(void *(*_A)(size_t), void (*_F)(void *))
  28.   {_Init(), _Palloc = _A, _Pfree = _F; }
  29.  strstreambuf(char *_G, int _N, char *_P = 0,
  30.   _Strstate _S = _Strzero)
  31.   {_Init(_N, _G, _P, _S); }
  32.  strstreambuf(unsigned char *_G, int _N,
  33.   unsigned char *_P = 0)
  34.   {_Init(_N, (char *)_G, (char *)_P); }
  35.  strstreambuf(const char *_G, int _N)
  36.   {_Init(_N, (char *)_G, 0, _Constant); }
  37.  strstreambuf(const unsigned char *_G, int _N)
  38.   {_Init(_N, (char *)_G, 0, _Constant); }
  39.  virtual ~strstreambuf();
  40.  void freeze(_Bool = 1);
  41.  char *str()
  42.   {freeze(); return (gptr()); }
  43.  int pcount() const
  44.   {return (pptr() == 0 ? 0 : pptr() - pbase()); } 
  45. #if _HAS_SIGNED_CHAR
  46.  strstreambuf(signed char *_G, int _N, signed char *_P = 0)
  47.   {_Init(_N, (char *)_G, (char *)_P); }
  48.  strstreambuf(const signed char *_G, int _N)
  49.   {_Init(_N, (char *)_G, 0, _Constant); }
  50. #endif /* _HAS_SIGNED_CHAR */
  51. protected:
  52.  virtual int overflow(int = EOF);
  53.  virtual int pbackfail(int = EOF);
  54.  virtual int underflow();
  55.  virtual streampos seekoff(streamoff, ios::seekdir,
  56.   ios::openmode = ios::in | ios::out);
  57.  virtual streampos seekpos(streampos,
  58.   ios::openmode = ios::in | ios::out);
  59.  void _Init(int = 0, char * = 0, char * = 0,
  60.   _Strstate = _Strzero);
  61.  void _Tidy();
  62.  _Strstate _Strmode;
  63. private:
  64.  char *_Pendsave, *_Seekhigh;
  65.  int _Alsize;
  66.  void *(*_Palloc)(size_t);
  67.  void (*_Pfree)(void *);
  68.  };
  69. _BITMASK_OPS(strstreambuf::__Strstate)
  70.   // class istrstream
  71. class istrstream : public istream {
  72. public:
  73.  istrstream(const char *_S)
  74.   : ios(&_Sb), istream(&_Sb), _Sb(_S, 0) {}
  75.  istrstream(const char *_S, int _N)
  76.   : ios(&_Sb), istream(&_Sb), _Sb(_S, _N) {}
  77.  istrstream(char *_S)
  78.   : ios(&_Sb), istream(&_Sb), _Sb((const char *)_S, 0) {}
  79.  istrstream(char *_S, int _N)
  80.   : ios(&_Sb), istream(&_Sb), _Sb((const char *)_S, _N) {}
  81.  virtual ~istrstream();
  82.  strstreambuf *rdbuf() const
  83.   {return ((strstreambuf *)&_Sb); }
  84.  char *str()
  85.   {return (_Sb.str()); }
  86. private:
  87.  strstreambuf _Sb;
  88.  };
  89.   // class ostrstream
  90. class ostrstream : public ostream {
  91. public:
  92.  ostrstream()
  93.   : ios(&_Sb), ostream(&_Sb), _Sb() {}
  94.  ostrstream(char *, int, openmode = out);
  95.  virtual ~ostrstream();
  96.  strstreambuf *rdbuf() const
  97.   {return ((strstreambuf *)&_Sb); }
  98.  void freeze(int _F = 1)
  99.   {_Sb.freeze(_F); }
  100.  char *str()
  101.   {return (_Sb.str()); }
  102.  int pcount() const
  103.   {return (_Sb.pcount()); }
  104. private:
  105.  strstreambuf _Sb;
  106.  };
  107.  
  108. #if __MWERKS__
  109. #if __CFM68K__ && __USING_IMPORTED_ANSI__
  110. #pragma import reset
  111. #endif
  112.  
  113. #pragma options align=reset
  114. #endif
  115.  
  116. #endif
  117.  
  118. /*
  119.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  120.  * Consult your license regarding permissions and restrictions.
  121.  */
  122.  
  123. /* Change log:
  124.  *94Oct03 Version received from PlumHall
  125.  *94Oct08 Inserted MW changes.
  126.  */
  127.